package com.caosy.grassthinkremote.aop;

import cn.hutool.core.collection.CollUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

@Aspect
@Component
public class InterviewAop {
    @Pointcut("execution(* com.caosy.grassthinkremote.controller.*.*(..))")
    public void interviewPointcut() {}

    @Before("interviewPointcut()")
    public void logBefore(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        String methodName = signature.getName();
        Object[] args = joinPoint.getArgs();
        ArrayList<Object> argList = CollUtil.newArrayList(args);
        String format = String.format("%s方法调用，参数：%s", methodName, argList);
        System.out.println(format);
    }
}
